<?php

namespace app\api\logic;

use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Dingtalk;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListDentriesHeaders;
use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListDentriesRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesHeaders;
use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesRequest\option;
use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesRequest;
class DingPan extends BaseSDKLogic
{
    public function createClient(){
        $config = new Config([]);
        $config->protocol = "https";
        $config->regionId = "central";
        return new Dingtalk($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public function main($args){
        $client = $this->createClient();
        $listDentriesHeaders = new ListDentriesHeaders([]);
        $listDentriesHeaders->xAcsDingtalkAccessToken = $this->accessToken();
        $listDentriesRequest = new ListDentriesRequest([
            "parentId" => "0",
//            "nextToken" => "next_token",
//            "maxResults" => 30,
//            "orderBy" => "MODIFIED_TIME",
//            "order" => "DESC",
//            "withThumbnail" => false,
            "unionId" => "yIuD7JiSmiPiSQuPjEv9Zii7SwiEiE"
        ]);

        $res = $client->listDentriesWithOptions("854xxxxx", $listDentriesRequest, $listDentriesHeaders, $this->runtimeOptions);

        return $res->body->result;
//        try {
//
//        }
//        catch (Exception $err) {
//            if (!($err instanceof TeaError)) {
//                $err = new TeaError([], $err->getMessage(), $err->getCode(), $err);
//            }
//            if (!Utils::empty_($err->code) && !Utils::empty_($err->message)) {
//                // err 中含有 code 和 message 属性，可帮助开发定位问题
//            }
//        }
    }


    public function index()
    {
        $client = self::createClient();
        $listAllDentriesHeaders = new ListAllDentriesHeaders([]);
        $listAllDentriesHeaders->xAcsDingtalkAccessToken = $this->accessToken();
//        $option = new option([
//            "nextToken" => "3678056xxxxx",
//            "maxResults" => 30,
//            "order" => "DESC",
//            "withThumbnail" => true
//        ]);
        $listAllDentriesRequest = new ListAllDentriesRequest([
            "unionId" => "yIuD7JiSmiPiSQuPjEv9Zii7SwiEiE",
//            "option" => $option
        ]);

        $r= $client->listAllDentriesWithOptions("314233097", $listAllDentriesRequest, $listAllDentriesHeaders, $this->runtimeOptions);


    }
}
